/**
*      author: Y_Yao
*      created: 2025-02-15 20:56:25
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
int n;

void solve()
{
    string s;
    cin >> n;
    cin >> s;
    vector<int> v;
    for (int i = 0; i < n; ++i) 
    {
        if (s[i] == '1') 
        {
            v.push_back(i + 1);
        }
    }
    int k = v.size();
    vector<int> t(k);
    for (int i = 0; i < k; ++i) 
    {
        t[i] = v[i] - i;
    }

    sort(t.begin(), t.end());

    int mid = t[k / 2];
    int ans = 0;
    for (int num : t) 
    {
        ans += abs(num - mid);
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
